<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/3 0003
 * Time: 下午 20:38
 */

namespace Home\Controller;

use Think\Controller;
use Think\Verify;

class RegisterController extends Controller
{
    public function index()
    {
        $this->display();
    }

    public function doreg()
    {
        $username = I('Aname');
        $password = I('Apassword');
        $code = I('check');
        $verify = new Verify();
        $user = M('admin')->where("Aname='{$username}'")->find();
        if (!$username) {
            $this->error('用户名不能为空');
        } elseif ($user) {
            $this->error('用户已存在');
        } elseif (!$password) {
            $this->error('密码不能为空');
        } elseif (!$code) {
            $this->error('验证码不能为空');
        } elseif (!$verify->check($code)) {
            $this->error('验证码错误');
        } else {
            $user = M('admin');
            $data = $user->create();
            $user->add($data);
            $this->success('注册成功', U('login/index'));
        }
    }

//        //验证码校验
//        //用户注册
//        if ($verify->check($code)) {
//            $this->success('成功');
//        } else {
//            $this->error('验证码错误');
//        }


    public function getVerify()
    {
        $config = array(
            'fontSize' => 30,    // 验证码字体大小
            'length' => 4,     // 验证码位数
            'useNoise' => false, // 关闭验证码杂点

        );
        $verify = new Verify($config);
        $verify->entry();
    }
}